
clear all

******************************************************************************
* Specify working directory
******************************************************************************

* For example
* cd "/Users/.../XYZ/"

global rawdata "Data/Raw_Data"
global tempdata "Data/Temp_Data"
global masterdata "Data/Master_Data"
global revisiondata "Data/RevisionRFS"
global revisionfigures = "Results/RevisionRFS/Figures"
global revisionoutput = "Results/RevisionRFS/Output"


/* -----------------------------------------------------------------------------

Generate Bond-specific Dummies based on Holdings

-----------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

#delimit ;

use "${revisiondata}/counterfactuals/counterfactuals_data.dta", clear;

gegen Tot_holding = sum(holding), by(bondid date);
gegen Fund_holding = sum(holding), by(fundid bondid date);
gegen Type_holding = sum(holding), by(type_new2 bondid date);

gen observed_holding_temp = Tot_holding - Fund_holding if type_new2 == 0;
gegen observed_holding = mean(observed_holding_temp), by(bondid date);
drop observed_holding_temp;

gen frac_type_holding_obs = Type_holding/observed_holding if type_new2 != 0;
gen frac_type_holding     = Type_holding/Tot_holding;


/* Life Insurance Dummies */
gen life_bond_temp = .;
replace life_bond_temp = 1 if frac_type_holding_obs > 0.4 & type_new2 == 1;
gegen life_bond = mean(life_bond_temp), by(bondid date);
drop life_bond_temp;

/* P&C Insurance Dummies */
gen pc_bond_temp = .;
replace pc_bond_temp = 1 if frac_type_holding_obs > 0.4 & type_new2 == 2;
gegen pc_bond = mean(pc_bond_temp), by(bondid date);
drop pc_bond_temp;

/* MF Dummies */
gen mf_bond_temp = .;
replace mf_bond_temp = 1 if frac_type_holding_obs > 0.4 & type_new2 == 3;
gegen mf_bond = mean(mf_bond_temp), by(bondid date);
drop mf_bond_temp;

/* VA Dummies */
gen va_bond_temp = .;
replace va_bond_temp = 1 if frac_type_holding_obs > 0.4 & type_new2 == 4;
gegen va_bond = mean(va_bond_temp), by(bondid date);
drop va_bond_temp;

/* ETF Dummies */
gen etf_bond_temp = .;
replace etf_bond_temp = 1 if frac_type_holding_obs > 0.25 & type_new2== 5;
gegen etf_bond = mean(etf_bond_temp), by(bondid date);
drop etf_bond_temp;

gcollapse life_bond pc_bond mf_bond va_bond etf_bond, by(bondid date);

replace life_bond = 0 if life_bond ==.;
replace pc_bond = 0 if pc_bond ==.;
replace mf_bond = 0 if mf_bond ==.;
replace va_bond = 0 if va_bond ==.;
replace etf_bond = 0 if etf_bond ==.;

save "${revisiondata}/counterfactuals/bond_holding_dummies.dta", replace;

#delimit cr


clear all
set more off

set varabbrev off

#delimit ;

use "${revisiondata}/counterfactuals/counterfactuals_data.dta", clear;

qui merge m:1 date fundid using "${revisiondata}/counterfactuals/Large_mf.dta";
drop if _merge == 2;
drop _merge;
replace large_mf = 0 if large_mf ==.;

gegen Tot_holding = sum(holding), by(bondid date);
gegen Fund_holding = sum(holding), by(fundid bondid date);
gegen Type_holding = sum(holding), by(large_mf bondid date);

gen observed_holding_temp = Tot_holding - Fund_holding if type_new2 == 0;
gegen observed_holding = mean(observed_holding_temp), by(bondid date);
drop observed_holding_temp;

gen frac_type_holding_obs = Type_holding/observed_holding if type_new2 != 0;
gen frac_type_holding     = Type_holding/Tot_holding;

/* Large MF Dummies */
gen large_mf_bond_temp = .;
replace large_mf_bond_temp = 1 if frac_type_holding_obs > 0.4 & large_mf == 1;
gegen large_mf_bond = mean(large_mf_bond_temp), by(bondid date);
drop large_mf_bond_temp;

gcollapse large_mf_bond, by(bondid date);

replace large_mf_bond = 0 if large_mf_bond ==.;

tab date if large_mf_bond == 1;

save "${revisiondata}/counterfactuals/large_mf_bond_dummies.dta", replace;

#delimit cr


clear all
set more off

set varabbrev off

#delimit ;

use "${revisiondata}/counterfactuals/counterfactuals_data.dta", clear;

qui merge m:1 date fundid using "${revisiondata}/counterfactuals/Illiquid_mf.dta";
drop if _merge == 2;
drop _merge;
replace illiquid_mf = 0 if illiquid_mf ==.;

gegen Tot_holding = sum(holding), by(bondid date);
gegen Fund_holding = sum(holding), by(fundid bondid date);
gegen Type_holding = sum(holding), by(illiquid_mf bondid date);

gen observed_holding_temp = Tot_holding - Fund_holding if type_new2 == 0;
gegen observed_holding = mean(observed_holding_temp), by(bondid date);
drop observed_holding_temp;

gen frac_type_holding_obs = Type_holding/observed_holding if type_new2 != 0;
gen frac_type_holding     = Type_holding/Tot_holding;

/* Large MF Dummies */
gen illiquid_mf_bond_temp = .;
replace illiquid_mf_bond_temp = 1 if frac_type_holding_obs > 0.4 & illiquid_mf == 1;
gegen illiquid_mf_bond = mean(illiquid_mf_bond_temp), by(bondid date);
drop illiquid_mf_bond_temp;

gcollapse illiquid_mf_bond, by(bondid date);

replace illiquid_mf_bond = 0 if illiquid_mf_bond ==.;

tab date if illiquid_mf_bond == 1;

save "${revisiondata}/counterfactuals/illiquid_mf_bond_dummies.dta", replace;

#delimit cr


#delimit ;

use "${revisiondata}/counterfactuals/counterfactuals_data.dta", clear;

qui merge m:1 date fundid using "${revisiondata}/counterfactuals/Large_etf.dta";
drop if _merge == 2;
drop _merge;
replace large_etf = 0 if large_etf ==.;

gegen Tot_holding = sum(holding), by(bondid date);
gegen Fund_holding = sum(holding), by(fundid bondid date);
gegen Type_holding = sum(holding), by(large_etf bondid date);

gen observed_holding_temp = Tot_holding - Fund_holding if type_new2 == 0;
gegen observed_holding = mean(observed_holding_temp), by(bondid date);
drop observed_holding_temp;

gen frac_type_holding_obs = Type_holding/observed_holding if type_new2 != 0;
gen frac_type_holding     = Type_holding/Tot_holding;

/* Large ETF Dummies */
gen large_etf_bond_temp = .;
replace large_etf_bond_temp = 1 if frac_type_holding_obs > 0.25 & large_etf == 1;
gegen large_etf_bond = mean(large_etf_bond_temp), by(bondid date);
drop large_etf_bond_temp;

gcollapse large_etf_bond, by(bondid date);

replace large_etf_bond = 0 if large_etf_bond ==.;

tab date if large_etf_bond == 1;

save "${revisiondata}/counterfactuals/large_etf_bond_dummies.dta", replace;



#delimit ;

use "${revisiondata}/counterfactuals/counterfactuals_data.dta", clear;

qui merge m:1 date fundid using "${revisiondata}/counterfactuals/HY_IG.dta";
drop if _merge == 2;
drop _merge;
replace HY_fund = 0 if HY_fund ==.;
replace HY_fund = 0 if type_new2 != 3;
replace IG_fund = 0 if IG_fund ==.;
replace IG_fund = 0 if type_new2 != 3;

gegen Tot_holding = sum(holding), by(bondid date);
gegen Fund_holding = sum(holding), by(fundid bondid date);
gegen Type_holding = sum(holding), by(HY_fund bondid date);

gen observed_holding_temp = Tot_holding - Fund_holding if type_new2 == 0;
gegen observed_holding = mean(observed_holding_temp), by(bondid date);
drop observed_holding_temp;

gen frac_type_holding_obs = Type_holding/observed_holding if type_new2 != 0;
gen frac_type_holding     = Type_holding/Tot_holding;

/* Large ETF Dummies */
gen HY_fund_bond_temp = .;
replace HY_fund_bond_temp = 1 if frac_type_holding_obs > 0.35 & HY_fund == 1;
gegen HY_fund_bond = mean(HY_fund_bond_temp), by(bondid date);
drop HY_fund_bond_temp;

gcollapse HY_fund_bond, by(bondid date);

replace HY_fund_bond = 0 if HY_fund_bond ==.;

tab date if HY_fund_bond == 1;

save "${revisiondata}/counterfactuals/HY_fund_bond_dummies.dta", replace;


#delimit ;

use "${revisiondata}/counterfactuals/counterfactuals_data.dta", clear;

qui merge m:1 date fundid using "${revisiondata}/counterfactuals/HY_IG.dta";
drop if _merge == 2;
drop _merge;
replace HY_fund = 0 if HY_fund ==.;
replace HY_fund = 0 if type_new2 != 3;
replace IG_fund = 0 if IG_fund ==.;
replace IG_fund = 0 if type_new2 != 3;

gegen Tot_holding = sum(holding), by(bondid date);
gegen Fund_holding = sum(holding), by(fundid bondid date);
gegen Type_holding = sum(holding), by(IG_fund bondid date);

gen observed_holding_temp = Tot_holding - Fund_holding if type_new2 == 0;
gegen observed_holding = mean(observed_holding_temp), by(bondid date);
drop observed_holding_temp;

gen frac_type_holding_obs = Type_holding/observed_holding if type_new2 != 0;
gen frac_type_holding     = Type_holding/Tot_holding;

/* Large ETF Dummies */
gen IG_fund_bond_temp = .;
replace IG_fund_bond_temp = 1 if frac_type_holding_obs > 0.35 & IG_fund == 1;
gegen IG_fund_bond = mean(IG_fund_bond_temp), by(bondid date);
drop IG_fund_bond_temp;

gcollapse IG_fund_bond, by(bondid date);

replace IG_fund_bond = 0 if IG_fund_bond ==.;

tab date if IG_fund_bond == 1;

save "${revisiondata}/counterfactuals/IG_fund_bond_dummies.dta", replace;



/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------------------------------------*/


/* -----------------------------------------------------------------------------

Counterfactual 2: Investment Grade Bonds Collectively Downgraded 

------------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_two_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_two_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)

/* -----------------------------------------------------------------------------

Figures 1 & 2: XS-Distribution over time - MF vs non-MF Bonds

------------------------------------------------------------------------------*/

preserve

gcollapse (median) diff_cs (p25) diff_cs25=diff_cs (p75) diff_cs75=diff_cs [w=mcap], by(date mf_bond) fast

twoway ///
(connected diff_cs date if mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 1, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_two_fig1.pdf", as(pdf) replace

twoway ///
(connected diff_cs date if mf_bond == 0, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 0, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_two_fig2.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 3: HY vs IG Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve


gcollapse diff_cs [w = mcap], by(date specgrade mf_bond)

egen id = group(specgrade mf_bond)
xtset id date


twoway ///
(connected diff_cs date if specgrade ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "HY MF") label(2 "HY") label(3 "IG MF") label(4 "IG") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_two_fig3.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 4: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve

gen maturity = . 
replace maturity = 1 if tmt_years <= 5
replace maturity = 2 if tmt_years > 5 & tmt_years <= 15
drop if maturity ==.

collapse diff_cs [w = mcap], by(date maturity mf_bond)

twoway ///
(connected diff_cs date if maturity ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "<5y MF") label(2 "<5y") label(3 ">5y MF") label(4 ">5y") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_two_fig4.pdf", as(pdf) replace

restore


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade) fast

su diff_cs if specgrade == 0 , d
su diff_cs if specgrade == 1 , d

restore


/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

restore


/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

restore



/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------------------------------------*/


/* -----------------------------------------------------------------------------

Counterfactual 3: High Yield Bonds Collectively Downgraded 

-----------------------------------------------------------------------------*/


clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_three_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_three_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)

/* -----------------------------------------------------------------------------

Figures 1 & 2: XS-Distribution over time - MF vs non-MF Bonds

------------------------------------------------------------------------------*/

preserve

gcollapse (median) diff_cs (p25) diff_cs25=diff_cs (p75) diff_cs75=diff_cs [w=mcap], by(date mf_bond) fast

twoway ///
(connected diff_cs date if mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 1, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_three_fig1.pdf", as(pdf) replace

twoway ///
(connected diff_cs date if mf_bond == 0, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 0, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_three_fig2.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 3: HY vs IG Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve


gcollapse diff_cs [w = mcap], by(date specgrade mf_bond)

egen id = group(specgrade mf_bond)
xtset id date


twoway ///
(connected diff_cs date if specgrade ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "HY MF") label(2 "HY") label(3 "IG MF") label(4 "IG") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_three_fig3.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 4: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve

gen maturity = . 
replace maturity = 1 if tmt_years <= 5
replace maturity = 2 if tmt_years > 5 & tmt_years <= 15
drop if maturity ==.

collapse diff_cs [w = mcap], by(date maturity mf_bond)

twoway ///
(connected diff_cs date if maturity ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "<5y MF") label(2 "<5y") label(3 ">5y MF") label(4 ">5y") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_three_fig4.pdf", as(pdf) replace

restore


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade) fast

su diff_cs if specgrade == 0 , d
su diff_cs if specgrade == 1 , d

restore

/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

restore


/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

restore


/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------------------------------------*/


/* -----------------------------------------------------------------------------

Counterfactual 4: Investment Grade Bonds Collectively Downgraded - Less Segmented

-----------------------------------------------------------------------------*/


clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_four_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_four_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)

/* -----------------------------------------------------------------------------

Figures 1 & 2: XS-Distribution over time - MF vs non-MF Bonds

------------------------------------------------------------------------------*/

preserve

gcollapse (median) diff_cs (p25) diff_cs25=diff_cs (p75) diff_cs75=diff_cs [w=mcap], by(date mf_bond) fast

twoway ///
(connected diff_cs date if mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 1, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_four_fig1.pdf", as(pdf) replace

twoway ///
(connected diff_cs date if mf_bond == 0, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 0, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_four_fig2.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 3: HY vs IG Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve


gcollapse diff_cs [w = mcap], by(date specgrade mf_bond)

egen id = group(specgrade mf_bond)
xtset id date


twoway ///
(connected diff_cs date if specgrade ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "HY MF") label(2 "HY") label(3 "IG MF") label(4 "IG") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_four_fig3.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 4: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve

gen maturity = . 
replace maturity = 1 if tmt_years <= 5
replace maturity = 2 if tmt_years > 5 & tmt_years <= 15
drop if maturity ==.

collapse diff_cs [w = mcap], by(date maturity mf_bond)

twoway ///
(connected diff_cs date if maturity ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "<5y MF") label(2 "<5y") label(3 ">5y MF") label(4 ">5y") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_four_fig4.pdf", as(pdf) replace

restore


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.

/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

restore


/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

restore


/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------------------------------------*/


/* -----------------------------------------------------------------------------

Counterfactual 5: High Yield Bonds Collectively Downgraded - Less Segmented

-----------------------------------------------------------------------------*/


clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_five_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_five_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)

/* -----------------------------------------------------------------------------

Figures 1 & 2: XS-Distribution over time - MF vs non-MF Bonds

------------------------------------------------------------------------------*/

preserve

gcollapse (median) diff_cs (p25) diff_cs25=diff_cs (p75) diff_cs75=diff_cs [w=mcap], by(date mf_bond) fast

twoway ///
(connected diff_cs date if mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 1, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_five_fig1.pdf", as(pdf) replace

twoway ///
(connected diff_cs date if mf_bond == 0, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 0, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_five_fig2.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 3: HY vs IG Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve


gcollapse diff_cs [w = mcap], by(date specgrade mf_bond)

egen id = group(specgrade mf_bond)
xtset id date


twoway ///
(connected diff_cs date if specgrade ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "HY MF") label(2 "HY") label(3 "IG MF") label(4 "IG") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_five_fig3.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 4: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve

gen maturity = . 
replace maturity = 1 if tmt_years <= 5
replace maturity = 2 if tmt_years > 5 & tmt_years <= 15
drop if maturity ==.

collapse diff_cs [w = mcap], by(date maturity mf_bond)

twoway ///
(connected diff_cs date if maturity ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "<5y MF") label(2 "<5y") label(3 ">5y MF") label(4 ">5y") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_five_fig4.pdf", as(pdf) replace

restore



/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.

/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

restore


/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

restore





/* -----------------------------------------------------------------------------

Counterfactual 6: ETF sector same size as in 2006Q1 --> AUM goes to MF

-----------------------------------------------------------------------------*/


clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_six_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_six_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

/* -----------------------------------------------------------------------------

Figures 1 & 2: XS-Distribution over time - MF vs non-MF Bonds

------------------------------------------------------------------------------*/

preserve

gcollapse (median) diff_cs (p25) diff_cs25=diff_cs (p75) diff_cs75=diff_cs [w=mcap], by(date mf_bond) fast

twoway ///
(connected diff_cs date if mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 1, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_six_fig1.pdf", as(pdf) replace

twoway ///
(connected diff_cs date if mf_bond == 0, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 0, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_six_fig2.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 3: HY vs IG Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve


gcollapse diff_cs [w = mcap], by(date specgrade mf_bond)

egen id = group(specgrade mf_bond)
xtset id date


twoway ///
(connected diff_cs date if specgrade ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "HY MF") label(2 "HY") label(3 "IG MF") label(4 "IG") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_six_fig3.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 4: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve

gen tmt_years = floor(timetomat)

gen maturity = . 
replace maturity = 1 if tmt_years <= 5
replace maturity = 2 if tmt_years > 5 & tmt_years <= 15
drop if maturity ==.

collapse diff_cs [w = mcap], by(date maturity mf_bond)

twoway ///
(connected diff_cs date if maturity ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "<5y MF") label(2 "<5y") label(3 ">5y MF") label(4 ">5y") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_six_fig4.pdf", as(pdf) replace

restore




/* -----------------------------------------------------------------------------

Counterfactual 9: MF sector same size as in 2006Q1 --> AUM goes to ETFs

-------------------------------------------------------------------------------*/


clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_nine_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_nine_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

/* -----------------------------------------------------------------------------

Figures 1 & 2: XS-Distribution over time - MF vs non-MF Bonds

------------------------------------------------------------------------------*/

preserve

gcollapse (median) diff_cs (p25) diff_cs25=diff_cs (p75) diff_cs75=diff_cs [w=mcap], by(date mf_bond) fast

twoway ///
(connected diff_cs date if mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 1, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_nine_fig1.pdf", as(pdf) replace

twoway ///
(connected diff_cs date if mf_bond == 0, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 0, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_nine_fig2.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 3: HY vs IG Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve


gcollapse diff_cs [w = mcap], by(date specgrade mf_bond)

egen id = group(specgrade mf_bond)
xtset id date


twoway ///
(connected diff_cs date if specgrade ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "HY MF") label(2 "HY") label(3 "IG MF") label(4 "IG") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_nine_fig3.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 4: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve

gen tmt_years = floor(timetomat)

gen maturity = . 
replace maturity = 1 if tmt_years <= 5
replace maturity = 2 if tmt_years > 5 & tmt_years <= 15
drop if maturity ==.

collapse diff_cs [w = mcap], by(date maturity mf_bond)

twoway ///
(connected diff_cs date if maturity ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "<5y MF") label(2 "<5y") label(3 ">5y MF") label(4 ">5y") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_nine_fig4.pdf", as(pdf) replace

restore




/* -----------------------------------------------------------------------------

Counterfactual 13: MF sector have same size as in 2006Q1 - proportionally

-----------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_thirteen_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_thirteen_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

/* -----------------------------------------------------------------------------

Figures 1 & 2: XS-Distribution over time - MF vs non-MF Bonds

------------------------------------------------------------------------------*/

preserve

gcollapse (median) diff_cs (p25) diff_cs25=diff_cs (p75) diff_cs75=diff_cs [w=mcap], by(date mf_bond) fast

twoway ///
(connected diff_cs date if mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 1, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_thirteen_fig1.pdf", as(pdf) replace

twoway ///
(connected diff_cs date if mf_bond == 0, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 0, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_thirteen_fig2.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 3: HY vs IG Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve


gcollapse diff_cs [w = mcap], by(date specgrade mf_bond)

egen id = group(specgrade mf_bond)
xtset id date


twoway ///
(connected diff_cs date if specgrade ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "HY MF") label(2 "HY") label(3 "IG MF") label(4 "IG") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_thirteen_fig3.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 4: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve

gen tmt_years = floor(timetomat)

gen maturity = . 
replace maturity = 1 if tmt_years <= 5
replace maturity = 2 if tmt_years > 5 & tmt_years <= 15
drop if maturity ==.

collapse diff_cs [w = mcap], by(date maturity mf_bond)

twoway ///
(connected diff_cs date if maturity ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "<5y MF") label(2 "<5y") label(3 ">5y MF") label(4 ">5y") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_thirteen_fig4.pdf", as(pdf) replace



/* -----------------------------------------------------------------------------

Counterfactual 14: Run on largest active MF - other active MF absorb 

------------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_fourteen_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_fourteen_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

merge m:1 date bondid using "${revisiondata}/counterfactuals/large_mf_bond_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)


/* -----------------------------------------------------------------------------

Figures 1 & 2: XS-Distribution over time - MF vs non-MF Bonds

------------------------------------------------------------------------------*/

preserve

gcollapse (median) diff_cs (p25) diff_cs25=diff_cs (p75) diff_cs75=diff_cs [w=mcap], by(date mf_bond) fast

twoway ///
(connected diff_cs date if mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 1, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_fourteen_fig1.pdf", as(pdf) replace

twoway ///
(connected diff_cs date if mf_bond == 0, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs25 date if mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs75 date if mf_bond == 0, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "median") label(2 "p25") label(3 "p75") order(1 2 3) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_fourteen_fig2.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 3: HY vs IG Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve


gcollapse diff_cs [w = mcap], by(date specgrade mf_bond)

egen id = group(specgrade mf_bond)
xtset id date


twoway ///
(connected diff_cs date if specgrade ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if specgrade ==0 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "HY MF") label(2 "HY") label(3 "IG MF") label(4 "IG") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_fourteen_fig3.pdf", as(pdf) replace

restore

/* -----------------------------------------------------------------------------

Figure 4: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

preserve

gen maturity = . 
replace maturity = 1 if tmt_years <= 5
replace maturity = 2 if tmt_years > 5 & tmt_years <= 15
drop if maturity ==.

collapse diff_cs [w = mcap], by(date maturity mf_bond)

twoway ///
(connected diff_cs date if maturity ==1 & mf_bond == 1, lwidth(medium) lpattern("l") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==1 & mf_bond == 0, lwidth(medium) lpattern(longdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 1, lwidth(medium) lpattern(shortdash) lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
(connected diff_cs date if maturity ==2 & mf_bond == 0, lwidth(medium) lpattern(".") lcolor(black) msymbol(i) mcolor(black) msize(small)) ///
, ///
title("", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.0f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(2) region(lwidth(none) color(none)) label(1 "<5y MF") label(2 "<5y") label(3 ">5y MF") label(4 ">5y") order(1 2 3 4) size(medium)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/cf_fourteen_fig4.pdf", as(pdf) replace


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.

/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

restore


/* LARGE MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_mf_bond) fast

su diff_cs if specgrade == 0 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & large_mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_mf_bond) fast

su diff_cs if specgrade == 0 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & large_mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 large_mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & large_mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & large_mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & large_mf_bond == 1, d

restore


/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

restore



/* -----------------------------------------------------------------------------

Counterfactual 15: Run on largest active MF - ETFs absorb 

------------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_fifteen_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_fifteen_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

merge m:1 date bondid using "${revisiondata}/counterfactuals/large_mf_bond_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.

/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

restore

/* LARGE MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_mf_bond) fast

su diff_cs if specgrade == 0 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & large_mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_mf_bond) fast

su diff_cs if specgrade == 0 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & large_mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 large_mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & large_mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & large_mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & large_mf_bond == 1, d

restore


/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

restore




/* -----------------------------------------------------------------------------

Counterfactual 16: Run on largest active MF - Life insurers absorb 

------------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_sixteen_184.dta", clear
forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {
	append using "${revisiondata}/counterfactuals/cf_sixteen_`q'.dta"
}

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

merge m:1 date bondid using "${revisiondata}/counterfactuals/large_mf_bond_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.

/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

restore


/* LARGE MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_mf_bond) fast

su diff_cs if specgrade == 0 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & large_mf_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_mf_bond) fast

su diff_cs if specgrade == 0 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & large_mf_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 large_mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & large_mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & large_mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & large_mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & large_mf_bond == 1, d

restore


/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

drop if date < `=tq(2008q3)'
drop if date > `=tq(2009q3)'

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

restore






/* -----------------------------------------------------------------------------

Counterfactual 17: Run on largest ETFs - MFs absorb 

------------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_seventeen_225.dta", clear
append using "${revisiondata}/counterfactuals/cf_seventeen_226.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_228.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_229.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_230.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_237.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_238.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_239.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_240.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_241.dta"
append using "${revisiondata}/counterfactuals/cf_seventeen_242.dta"

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

merge m:1 date bondid using "${revisiondata}/counterfactuals/large_etf_bond_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.


/* LARGE ETF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_etf_bond) fast

su diff_cs if specgrade == 0 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & large_etf_bond == 1, d

keep if large_etf_bond == 1
tabstat diff_cs, s(median) by(specgrade)


restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 large_etf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & large_etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & large_etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & large_etf_bond == 1, d

keep if large_etf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore


/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

keep if mf_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

keep if mf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore


/* ETF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade etf_bond) fast

su diff_cs if specgrade == 0 & etf_bond == 1, d
su diff_cs if specgrade == 1 & etf_bond == 1, d

keep if etf_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 etf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & etf_bond == 1, d

keep if etf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore



/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

keep if life_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

keep if life_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)


restore



/* -----------------------------------------------------------------------------

Counterfactual 18: Run on largest ETFs - ETFs absorb 

------------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_eightteen_225.dta", clear
append using "${revisiondata}/counterfactuals/cf_eightteen_226.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_228.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_229.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_230.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_237.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_238.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_239.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_240.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_241.dta"
append using "${revisiondata}/counterfactuals/cf_eightteen_242.dta"

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

merge m:1 date bondid using "${revisiondata}/counterfactuals/large_etf_bond_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.


/* LARGE ETF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_etf_bond) fast

su diff_cs if specgrade == 0 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & large_etf_bond == 1, d

keep if large_etf_bond == 1
tabstat diff_cs, s(median) by(specgrade)


restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 large_etf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & large_etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & large_etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & large_etf_bond == 1, d

keep if large_etf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore


/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

keep if mf_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

keep if mf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore


/* ETF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade etf_bond) fast

su diff_cs if specgrade == 0 & etf_bond == 1, d
su diff_cs if specgrade == 1 & etf_bond == 1, d

keep if etf_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 etf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & etf_bond == 1, d

keep if etf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore



/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

keep if life_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

keep if life_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)


restore




/* -----------------------------------------------------------------------------

Counterfactual 19: Run on largest ETFs - Life insurer absorb 

------------------------------------------------------------------------------*/

clear all
set more off

set varabbrev off

/* Merge and Load Data */

use "${revisiondata}/counterfactuals/cf_nineteen_225.dta", clear
append using "${revisiondata}/counterfactuals/cf_nineteen_226.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_228.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_229.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_230.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_237.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_238.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_239.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_240.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_241.dta"
append using "${revisiondata}/counterfactuals/cf_nineteen_242.dta"

winsor2 CF_chg_yield, replace by(type_new2 date) cuts(1 99)

gen diff_cs = 100*CF_chg_yield

gen specgrade = 0
replace specgrade = 1 if rating_numLoop >= 11

/* Original Market Cap of a Bond to value-weight results */
gen mcap = exp(LNbv)*exp(ln_mp)

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"
drop _merge

merge m:1 date bondid using "${revisiondata}/counterfactuals/large_etf_bond_dummies.dta"
drop _merge

gen tmt_years = floor(timetomat)


/* -----------------------------------------------------------------------------

Table: Short- vs Long-term Bonds - MF vs non-MF Bonds 

------------------------------------------------------------------------------*/

gen maturity2 = . 
replace maturity2 = 1 if tmt_years <= 5
replace maturity2 = 2 if tmt_years > 5 & tmt_years <= 10
replace maturity2 = 3 if tmt_years > 10
drop if maturity2 ==.


/* LARGE ETF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade large_etf_bond) fast

su diff_cs if specgrade == 0 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & large_etf_bond == 1, d

keep if large_etf_bond == 1
tabstat diff_cs, s(median) by(specgrade)


restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 large_etf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & large_etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & large_etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & large_etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & large_etf_bond == 1, d

keep if large_etf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore


/* MF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade mf_bond) fast

su diff_cs if specgrade == 0 & mf_bond == 1, d
su diff_cs if specgrade == 1 & mf_bond == 1, d

keep if mf_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 mf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & mf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & mf_bond == 1, d

keep if mf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore


/* ETF BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade etf_bond) fast

su diff_cs if specgrade == 0 & etf_bond == 1, d
su diff_cs if specgrade == 1 & etf_bond == 1, d

keep if etf_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 etf_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & etf_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & etf_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & etf_bond == 1, d

keep if etf_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)

restore



/* LIFE BONDS */

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade life_bond) fast

su diff_cs if specgrade == 0 & life_bond == 1, d
su diff_cs if specgrade == 1 & life_bond == 1, d

keep if life_bond == 1
tabstat diff_cs, s(median) by(specgrade)

restore

preserve

gcollapse (median) diff_cs [w=mcap], by(date specgrade maturity2 life_bond) fast

su diff_cs if specgrade == 0 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 0 & maturity2 == 3 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 1 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 2 & life_bond == 1, d
su diff_cs if specgrade == 1 & maturity2 == 3 & life_bond == 1, d

keep if life_bond == 1
gegen id = group(specgrade maturity2)
tabstat diff_cs, s(median) by(id)


restore




